<?php 
	$table = "catalog";	
	
	$pageSize = 20;
    $pageNum = 1;
    if (isset($_GET['pageNum']) == true)
        $pageNum = $_GET['pageNum'];
    else
        $pageNum = 1;
    $startRow = ($pageNum-1)*$pageSize;
    $endRow = $startRow + $pageSize;
    $totalRows = $conn->get_maxrow_of_table($table);
	
	$list_record = $conn->get_all_data($table, -1, 1, $option1, $option2 = ' LIMIT '.$startRow.','.$pageSize.'');
?>
<p>
	<a class="btn btn-primary" href="index.php?p=<?=$table ?>&t=add">Thêm danh mục</a>
</p>
<table class="table table-bordered">
	<tr>
		<th width="20">#</th>		
		<th>Tên menu</th>
		<th>Catalog2</th>
		<th>Công cụ</th>
	</tr>
	<?php
        foreach ($list_record as $k => $value) {
        	$list_catalog2 = $conn -> get_all_data_fix($table = 'catalog1', -1, 1, $option1 = ' AND catalog_id='.$value['id'] , $option2 = ' ORDER BY count DESC')
    ?>
	<tr>
		<td><?=$k+1?></td>
		<td><?=$value['title']  ?></td>
		<td>
			<table class="table">
				<tr>
					<th width="20">#</th>
					<th>Tên menu</th>
					<th>Công cụ</th>
				</tr>
				<tr>
					<td colspan="3">
						<a class="btn" href="index.php?p=catalog1&t=add&catalog_id=<?=$value['id']  ?>">
							<i class="icon-plus"></i>
						</a>
					</td>
				</tr>
				<?php foreach ($list_catalog2 as $key => $value2): ?>
				<tr>
					<td><?=$key+1?></td>
					<td><?=$value2['title']  ?></td>
					<td>
						<a rel="tooltip" data-original-title="Sửa" href="index.php?p=catalog1&t=edit&catalog_id=<?=$value['id']  ?>&id=<?=$value2['id'] ?>" title="Sửa">
							<i class="icon-edit"></i>
						</a>
						<a rel="tooltip" data-original-title="Xóa" href="javascript:void(0)" onclick="if (confirm('Are you sure ?')) dashboard.admin.delete_record('<?php echo 'catalog1'; ?>','<?php echo $value2['id']; ?>');" title="Xóa">
							<i class="icon-remove"></i>
						</a>
					</td>
				</tr>	
				<?php endforeach ?>
			</table>
		</td>
		<td>
			<a rel="tooltip" data-original-title="Sửa" href="index.php?p=<?=$table = 'catalog' ?>&t=edit&id=<?=$value['id'] ?>" title="Sửa">
				<i class="icon-edit"></i>
			</a>
			<a rel="tooltip" data-original-title="Xóa" href="javascript:void(0)" onclick="if (confirm('Are you sure ?')) dashboard.admin.delete_record('<?php echo $table; ?>','<?php echo $value['id']; ?>');" title="Xóa">
				<i class="icon-remove"></i>
			</a>
		</td>
	</tr>
	<? } ?>
</table>
<div class="pagination">
	<ul class="pull-right">
		<?php echo $conn->pageList($totalRows, $pageNum, $pageSize); ?>
	</ul>
</div>